<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心灵笔触</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/logout.js"></script>

    <style>
        login-dialog {
            width: 400px;
            height: 400px;
            background-color: rgba(255, 255, 255, 0.8);
            border-radius: 10px;
        }

        .login-dialog h1 {
            font-size: 30px;
            padding: 50px 0;
            text-align: center;
        }

        .login-dialog .row {
            height: 50px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .login-dialog .row span {
            font-size: 19px;
            display: block;
            width: 100px;
            font-weight: 700;
        }

        .login-dialog .row input {
            width: 430px;
            height: 45px;
            line-height: 40px;
            font-size: 24px;
            border-radius: 10px;
            border: none;
            outline: none;
            text-indent: 10px;
        }

        .login-dialog button {
            width: 300px;
            height: 50px;
            color: white;
            background-color: black;
            border: none;
            border-radius: 10px;
        }

        .login-dialog button:active {
            background-color: #666;
        }

        ::placeholder {
            font-size: 15px;
            /* 在这里设置所需的字体大小 */
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo2.jpg" alt="">
        <span class="title">心灵笔触</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list2.html?pindex=1">主页</a>
        <a href="blog_add.html">创作</a>
        <a href="javascript:logout()">退出</a>
        <script src="js/urlutis.js"></script>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img id="img" src="" class="avtar" alt="">
                <h3 id="username"></h3>
                <h3>作者</h3>
                <div class="counter">
                    <span>书籍</span>
                </div>
                <div class="counter">
                    <span id="artcount"></span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="login-dialog">
                <h1>修改信息</h1>
                <div class="row">
                    <span>文章名</span>
                    <input type="text" id="title" placeholder="可选">
                </div>
                <br>
                <div class="row">
                    <span>类型</span>
                    <input type="text" id="type" placeholder="可选">
                </div>
                <br>
                <br>
                <div class="row">
                    <a href="#" onclick="toupdate()" style="text-decoration: none; color: black;">修改内容 >></a>
                </div>
                <br>
                <div class="row">
                    <button id="submit" onclick="mysub()">提 交</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var aid = getParamValue("aid");

        var editormd;
        function initEdit(md) {
            editormd = editormd.markdownToHTML("editorDiv", {
                markdown: md, // Also, you can dynamic set Markdown text
                // htmlDecode : true,  // Enable / disable HTML tag encode.
                // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
            });
        }

        // 初始化页面（根据文章 id 先得到文章信息）
        function init() {
            // 1. 效验参数
            if (aid == null || aid <= 0) {
                alert("参数有误！");
                return false;
            }
            // 2. 请求后端获得数据
            jQuery.ajax({
                url: "/art/detail",
                type: "GET",
                data: {
                    "aid": aid
                },
                success: function (res) {
                    // 3. 将数据展示到前端
                    if (res.code == 200 && res.data != null) {
                        var user = res.data.user;
                        var art = res.data.art;
                        if (user != null) {
                            // 给用户对象设置值
                            if (user.photo != "") {
                                jQuery("#photo").attr("src", user.photo);
                            }
                            jQuery("#username").html(user.username);
                            jQuery("#artcount").html(user.artCount);
                        } else {
                            alert("抱歉，查看失败！" + res.msg);
                        }
                    } else {
                        alert("抱歉，查看失败！" + res.msg);
                    }
                }
            });

            var img = jQuery("#img");
            var imgUrl = "img/";

            // 初始化用户头像
            jQuery.ajax({
                url: "/user/photoall",
                type: "GET",
                data: {
                    "aid":aid
                },
                success: function (res) {
                    // alert(res.data);
                    if (res.code == 200 && res.data != "") {
                        imgUrl += res.data;
                        img.attr('src', imgUrl);
                    } else if (res.data == "") {
                        img.attr('src', "img/avatar.png");
                    } else {
                        alert("初始化失败" + res.msg);
                    }
                }
            });
        }
        init();

        function mysub() {
            var title = jQuery("#title");
            console.log(title.val());
            var type = jQuery("#type");
            var time = jQuery("#time");
            if (title.val().trim() == "" && type.val().trim() == "" && time.val().trim() == "") {
                alert("请至少修改一种信息！");
                return false;
            }
            jQuery.ajax({
                url:"/art/updatebook",
                type:"POST",
                data:{
                    "title": title.val(),
                    "type": type.val(),
                    "time": time.val(),
                    "id": aid
                },
                success: function(res) {
                    if(res.code == 200 && res.data != null) {
                        alert("修改成功！");
                        location.href = "myblog_list.html";
                    } else {
                        alert("修改失败！" + res.msg);
                    }
                }
            });

           
        }

        // 修改内容
        function toupdate() {
            location.href = "blog_edit.html?aid=" + aid;
        }
    </script>
</body>

</html>